﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HotelProject
{
    public partial class Users : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        /// <summary>
        /// When the add user button is clicked, a new user is created using the data in the text boxes and adds them to the database.
        /// the gridview then refreshes reflecting the data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void createNewUserButton_Click(object sender, EventArgs e)
        {
            if (userNameTextBox.Text != "" || firstNameTextBox.Text != "" || lastNameTextBox.Text != ""
                || passwordTextBox.Text != "")
            {
                MySQLDatabaseConnector database = new MySQLDatabaseConnector();
                registeredUser newUser = new registeredUser();
                newUser.userName = userNameTextBox.Text;
                newUser.userFirstName = firstNameTextBox.Text;
                newUser.userLastName = lastNameTextBox.Text;
                newUser.userPassword = passwordTextBox.Text;
                newUser.isAdmin = adminCheckBox.Checked;

                database.addUser(newUser);
                database.saveChanges();
                GridView1.DataBind();

                userNameTextBox.Text = "";
                firstNameTextBox.Text = "";
                lastNameTextBox.Text = "";
                passwordTextBox.Text = "";
                adminCheckBox.Checked = false;
            }
          

            


        }
    }
}